package com.hzdl.car.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzdl.car.bean.News;
import com.hzdl.car.mapper.NewsMapper;
import com.hzdl.car.service.NewsService;
import com.hzdl.car.vo.NewsVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service
public class NewsServiceImpl implements NewsService {
    @Resource
    private NewsMapper newsMapper;
    @Override
    public PageInfo<News> findNews(NewsVo newsVo) {
        PageHelper.startPage(newsVo.getPage(),newsVo.getLimit());
        List<News> list=newsMapper.findNews(newsVo);
        PageInfo<News> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int addNews(NewsVo newsVo) {
        return newsMapper.addNews(newsVo);
    }

    @Override
    public int dekNews(NewsVo newsVo) {
        return newsMapper.dekNews(newsVo);
    }

    @Override
    public int newsDelChk(Integer[] ids) {
        int row=0;
        for (Integer i:ids){
            NewsVo newsVo=new NewsVo();
            newsVo.setId(i);
            row+=newsMapper.dekNews(newsVo);
        }
        return row;
    }

    @Override
    public int newsUpdate(NewsVo newsVo) {
        return newsMapper.newsUpdate(newsVo);
    }

    @Override
    public PageInfo<News> showNews() {
        PageInfo pageInfo=new PageInfo(newsMapper.showNews());
        return pageInfo;
    }
}
